@tool
class_name Skill_Action_GenerateGO
extends SkillAction

#region 属性
@export var parallel:bool = false
@export var scenes:Array[PackedScene]
@export var rounds:Array[Skill_GenerateRound]
var tween:Tween
var cur_idx:int = -1
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
## 初始化
func init(action_idx:int = -1,init_data:Dictionary = {},handle_func:Callable = Callable()):
	var self_handle_func = func():
		if handle_func.is_valid():
			handle_func.call()
		Utils.array_for_each(rounds,func(round:Skill_GenerateRound):
			round.init(self,scenes)
			)
	super.init(action_idx,init_data,self_handle_func)
## 释放
func release(args:Dictionary = {},handle_func:Callable = Callable()):
	var self_handle_func = func():
		if handle_func.is_valid():
			handle_func.call()
		if tween != null and tween.is_valid():
			tween.play()
		else:
			if parallel:
				tween = create_tween()
				tween.parallel()
				for round in rounds:
					tween.tween_callback(func():round.create_tween())
				tween.finished.connect(func():
					complete()
				)
			else:
				_sequence_func()
	super.release(args,self_handle_func)
## 打断
func interrupt(handle_func:Callable = Callable()):
	var self_handle_func = func():
		if handle_func.is_valid():
			handle_func.call()
		if tween != null and tween.is_valid():
			tween.kill()
			tween = null
	super.interrupt(self_handle_func)
## 完成
func complete(release_result:GameEnum.SkillReleaseResult = GameEnum.SkillReleaseResult.Success,handle_func:Callable = Callable()):
	var self_handle_func = func():
		if handle_func.is_valid():
			handle_func.call()
		if tween != null and tween.is_valid():
			tween.kill()
			tween = null
	super.complete(release_result,self_handle_func)
## 冷却
func cool(handle_func:Callable = Callable()):
	var self_handle_func = func():
		if handle_func.is_valid():
			handle_func.call()
	super.cool(self_handle_func)
## 冷却完成
func cool_complete(handle_func:Callable = Callable()):
	var self_handle_func = func():
		if handle_func.is_valid():
			handle_func.call()
		cur_idx = -1
	super.cool_complete(self_handle_func)
## 重置冷却
func reset_cool(handle_func:Callable = Callable()):
	var self_handle_func = func():
		if handle_func.is_valid():
			handle_func.call()
		cur_idx = -1
		if tween != null and tween.is_valid():
			tween.kill()
			tween = null
	super.reset_cool(self_handle_func)
## 销毁
func destroy(handle_func:Callable = Callable()):
	var self_handle_func = func():
		if handle_func.is_valid():
			handle_func.call()
		if tween != null and tween.is_valid():
			tween.kill()
			tween = null
	super.destroy(self_handle_func)
## 判断该技能能否释放
func check_can_release() -> GameEnum.SkillReleaseStatus:
	var res = super.check_can_release()
	if res != GameEnum.SkillReleaseStatus.Success:
		return res
	return GameEnum.SkillReleaseStatus.Success
func check_is_completed() -> bool:
	return is_completed
#endregion
#region 公共方法
#endregion
#region 私有方法
func _sequence_func():
	cur_idx += 1
	if cur_idx >= rounds.size():
		is_completed = true
		complete()
		tween = null
	else:
		tween = rounds[cur_idx].create_tween()
		tween.finished.connect(func():
			_sequence_func()
		)
#endregion
#region 生命周期函数
#endregion
